package com.zmn.oms.services.impl.ins;

import com.zmn.oms.model.entity.ins.InsOrderMasterSync;
import com.zmn.oms.persistence.interfaces.ins.InsOrderMasterSyncDao;
import com.zmn.oms.services.interfaces.ins.InsOrderMasterSyncService;
import com.zmn.oms.services.interfaces.orderencrypt.InsOrderEncryptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述：
 *
 * @author lhl
 * @date 2020/06/01 19:01
 */
@Service("insOrderMasterSyncService")
public class InsOrderMasterSyncServiceImpl implements InsOrderMasterSyncService {

    @Resource
    private InsOrderMasterSyncDao insOrderMasterSyncDao;
    @Autowired
    private InsOrderEncryptService insOrderEncryptService;

    @Override
    public List<InsOrderMasterSync> listNoSynced(Integer rows) {
        List<InsOrderMasterSync> insOrderMasterSyncs = insOrderMasterSyncDao.listNoSynced(rows);
        return insOrderEncryptService.batchDecryptInsOrderMasterSync(insOrderMasterSyncs);
    }

    @Override
    @Transactional
    public void updateSyncPendingByKeys(List<Long> insMasterSyncIdList) {
        insOrderMasterSyncDao.updateSyncedSuccessByKeys(insMasterSyncIdList);
    }

    @Override
    @Transactional
    public void updateUnSyncedByKeys(List<Long> insMasterSyncIdList) {
        insOrderMasterSyncDao.updateSyncedSuccessByKeys(insMasterSyncIdList);
    }

    @Override
    @Transactional
    public void updateSyncedSuccessByKeys(List<Long> insMasterSyncIdList) {
        insOrderMasterSyncDao.updateSyncedSuccessByKeys(insMasterSyncIdList);
    }

    @Override
    @Transactional
    public void updateSyncedFailByKeys(List<Long> insMasterSyncIdList) {
        insOrderMasterSyncDao.updateSyncedFailByKeys(insMasterSyncIdList);
    }

    @Override
    public int insertInsOrderMasterSync(InsOrderMasterSync insOrderMasterSync) {
        InsOrderMasterSync insOrderMasterSyncCopy = insOrderEncryptService.encryptInsOrderMasterSync(insOrderMasterSync);
        int count = insOrderMasterSyncDao.insertInsOrderMasterSync(insOrderMasterSync);
        insOrderMasterSync.setInsMasterSyncId(insOrderMasterSyncCopy.getInsMasterSyncId());
        return count;
    }
}
